#ifndef __MAPFILEREADER__
#define __MAPFILEREADER__

#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>

using namespace std;

class MapField{
	string markerid;
	unsigned short chr;
	// genetic distance
	double distance;
	// physical position
	unsigned int pos;
	
public:
	MapField(string input){
		istringstream iss(input);
		iss >> chr >> markerid >> distance >> pos;
	}
	const string &get_markerid() const{
		return markerid;
	}
	const unsigned short &get_chr() const{
		return chr;
	}
	const unsigned int &get_pos() const{
		return pos;
	}
};

// reads PLINK .map file
class MapFileReader{
private:
	char* filename;
	vector<MapField*> mapvec;
public:
	// constructor opens file
	MapFileReader(char* str);
	const string get_filename() const{
		return filename;
	}
	const vector<MapField*>& get_mapvec() const{
		return mapvec;
	}
	struct mapvec_comp{
		bool operator()(MapField const* a, MapField const* b){
			if (a->get_chr()  < b->get_chr()) {
				return true;
			} else if (a->get_chr() > b->get_chr()){
				return false;
			} else {
				if (a->get_pos() < b->get_pos()){
					return true;
				}
				else {
					return false;
				}
			}
		}
	};
};

#endif